package com.lcj.workflow.controller;

import cn.hutool.core.bean.BeanUtil;
import com.lcj.common.util.Result;
import com.lcj.workflow.controller.form.AcceptCommentAppealForm;
import com.lcj.workflow.controller.form.HandleCommentAppealForm;
import com.lcj.workflow.controller.form.SearchAppealContentForm;
import com.lcj.workflow.controller.form.StartCommentWorkflowForm;
import com.lcj.workflow.service.OrderCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;

@RestController
@RequestMapping({"/comment"})
@Tag(name = "OrderController", description = "订单评价工作流Web接口")
public class OrderCommentController {
    @Resource
    private OrderCommentService orderCommentService;

    @PostMapping({"/handleCommentAppeal"})
    @Operation(summary = "处理评价申诉")
    public Result handleCommentAppeal(@RequestBody @Valid HandleCommentAppealForm handleCommentAppealForm) {
        this.orderCommentService.handleCommentAppeal(BeanUtil.beanToMap(handleCommentAppealForm));
        return Result.ok();
    }

    @PostMapping({"/acceptCommentAppeal"})
    @Operation(summary = "受理评价申诉")
    public Result acceptCommentAppeal(@RequestBody @Valid AcceptCommentAppealForm acceptCommentAppealForm) {
        orderCommentService.acceptCommentAppeal(BeanUtil.beanToMap(acceptCommentAppealForm));
        return Result.ok();
    }

    @PostMapping({"/searchAppealContent"})
    @Operation(summary = "查询审批工作流内容")
    public Result searchAppealContent(@RequestBody @Valid SearchAppealContentForm searchAppealContentForm) {
        return Result.ok().put("result", orderCommentService.searchAppealContent(searchAppealContentForm.getInstanceId(), searchAppealContentForm.getIsEnd().booleanValue()));
    }

    @PostMapping({"/startCommentWorkflow"})
    @Operation(summary = "开启评价申诉工作流")
    public Result startCommentWorkflow(@RequestBody @Valid StartCommentWorkflowForm startCommentWorkflowForm) {
        HashMap<Object, Object> hashMap = new HashMap<>();
        hashMap.put("orderId", startCommentWorkflowForm.getOrderId().toString());
        hashMap.put("driverId", startCommentWorkflowForm.getDriverId().toString());
        hashMap.put("customerId", startCommentWorkflowForm.getCustomerId().toString());
        hashMap.put("reason", startCommentWorkflowForm.getReason());
        orderCommentService.startCommentWorkflow(hashMap);
        return Result.ok();
    }
}
